from django.db import models


class FinancialStatement(models.Model):
    year = models.IntegerField(verbose_name='财务报表年份', help_text='请输入财务报表对应的年份')
    total_assets = models.DecimalField(max_digits=15, decimal_places=2, verbose_name='总资产',
                                       help_text='请输入公司的总资产')
    total_liabilities = models.DecimalField(max_digits=15, decimal_places=2, verbose_name='总负债',
                                            help_text='请输入公司的总负债')
    equity = models.DecimalField(max_digits=15, decimal_places=2, verbose_name='股东权益',
                                 help_text='请输入公司的股东权益')
    revenue = models.DecimalField(max_digits=15, decimal_places=2, verbose_name='营业收入',
                                  help_text='请输入公司的营业收入')
    net_profit = models.DecimalField(max_digits=15, decimal_places=2, verbose_name='净利润',
                                     help_text='请输入公司的净利润')
    operating_cash_flow = models.DecimalField(max_digits=15, decimal_places=2, verbose_name='经营现金流',
                                              help_text='请输入公司的经营现金流')

    class Meta:
        verbose_name = '财务报表'
        verbose_name_plural = '财务报表'

    def __str__(self):
        return f'{self.year} 财务报表'

    def save(self, *args, **kwargs):
        # 可以在此加入自定义保存逻辑
        super().save(*args, **kwargs)


class FinancialHealthIndex(models.Model):
    statement = models.ForeignKey(FinancialStatement, on_delete=models.CASCADE, related_name='health_indices',
                                  verbose_name='财务报表')
    profitability_index = models.DecimalField(max_digits=5, decimal_places=2, verbose_name='盈利能力指数',
                                              help_text='公司盈利能力的评估指标')
    solvency_index = models.DecimalField(max_digits=5, decimal_places=2, verbose_name='偿债能力指数',
                                         help_text='公司偿还债务的能力')
    efficiency_index = models.DecimalField(max_digits=5, decimal_places=2, verbose_name='运营效率指数',
                                           help_text='公司运营效率的评估')
    overall_health_index = models.DecimalField(max_digits=5, decimal_places=2, verbose_name='总体健康指数',
                                               help_text='公司财务健康的综合评分')

    class Meta:
        verbose_name = '财务健康指数'
        verbose_name_plural = '财务健康指数'

    def __str__(self):
        return f'{self.statement.year} 财务健康指数'

    def save(self, *args, **kwargs):
        # 可以在此加入自定义保存逻辑
        super().save(*args, **kwargs)
